﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lexer
{
    /// <summary>
    /// A class specifying what a lexerToken looks like.
    /// </summary>
    class LexerToken
    {
        private readonly TokenType type;
        
        public TokenType Type
        {
            get { return type; }
        }

        private readonly String stringValue;

        public String StringValue
        {
            get { return this.stringValue; }
        }

        private readonly int intValue;

        public int IntValue
        {
            get { return intValue; }
        }

        public LexerToken(TokenType tknType, String value)
        {
            this.type = tknType;
            this.stringValue = value;
            this.intValue = -1;
        }

        public LexerToken(TokenType tknType, int value)
        {
            this.type = tknType;
            this.stringValue = "";
            this.intValue = value;
        }

        public override string ToString()
        {
            switch(this.type)
            {
                case TokenType.NUMBER_LITERAL:
                    return this.type.ToString() + ": " + this.intValue;
                case TokenType.STRING_LITERAL:
                case TokenType.OPCODE:
                case TokenType.IDENTIFIER:
                case TokenType.KEYWORD:
                case TokenType.PROPERTY:
                    return this.type.ToString() + ": " + this.stringValue;
                default:
                    return this.type.ToString();
            }
        }
        public override bool Equals(object obj)
        {
            if (obj is LexerToken)
            {
                LexerToken tkn = obj as LexerToken;
                return tkn.intValue == this.intValue && tkn.stringValue == this.stringValue && tkn.type == this.type;
            }
            return base.Equals(obj);
        }
    }
    /// <summary>
    /// Types of tokens.
    /// </summary>
    enum TokenType
    {
        KEYWORD, OPCODE, OPEN_BRACE, CLOSE_BRACE, OPEN_PAREN, CLOSE_PAREN, IDENTIFIER, STRING_LITERAL, NUMBER_LITERAL, PROPERTY, END_LINE, END_OF_FILE
    }
}
